IS NOT NULL

Course- MariaDB >

This MariaDB tutorial explains how to use the MariaDB IS NOT NULL condition with syntax and examples.

Description

The MariaDB IS NOT NULL condition is used to test for a NOT NULL value in a SELECT, INSERT, UPDATE, or DELETE statement.

Syntax

The syntax for the IS NOT NULL condition in MariaDB is:

expression IS NOT NULL

Parameters or Arguments

expression

The value to test whether it is a non-NULL value.

Note

  • If expression is NOT a NULL value, the condition evaluates to TRUE.
  • If expression is a NULL value, the condition evaluates to FALSE.
  • See also the IS NULL condition in MariaDB.

Example - With SELECT Statement

Let's look at an example of how to use the IS NOT NULL condition in a SELECT statement in MariaDB.

For example:

SELECT *

FROM sites

WHERE site_name IS NOT NULL;

This IS NOT NULL example will return all records from the sites table where the site_name does not contain a NULL value.

Example - With INSERT Statement

Let's look at how to use the IS NOT NULL condition in an INSERT statement in MariaDB.

For example:

INSERT INTO contacts

(contact_id, contact_name)

SELECT site_id, site_name

FROM sites

WHERE site_name = 'Fastread.aitechtonic.com'

AND server_name IS NOT NULL;

This MariaDB IS NOT NULL example will insert records into the sites table where the site_name is 'Fastread.aitechtonic.com' and the server_name contains does not contain a NULL value.

Example - With UPDATE Statement

Let's look at an example in MariaDB of how to use the IS NOT NULL condition in an UPDATE statement.

For example:

UPDATE sites

SET server_name = 'MyServer'

WHERE site_name IS NOT NULL;

This IS NOT NULL example will update records in the sites table where the site_name does not contain a NULL value.

Example - With DELETE Statement

Let's look at an example of how to use the IS NOT NULL condition in a DELETE statement in MariaDB.

For example:

DELETE FROM sites

WHERE server_name IS NOT NULL;

This MariaDB IS NOT NULL example will delete all records from the sites table where the server_name does not contain a NULL value.